<template>
  <div>
    <!-- navbar -->
    <!-- <van-nav-bar title="爱阅之城" fixed>
      <template #left @click-left="onClickLeft">
        <van-icon name="ellipsis" size="18" />
      </template>
      <template #right @click-left="onClickRight">
        <van-icon name="ellipsis" size="18" />
      </template>
    </van-nav-bar> -->
    <!-- search -->
    <van-search
      shape="round"
      background="#fff"
      placeholder="请输入搜索书籍名称"
      v-for="(item, index) in book"
      :key="index"
      v-model="serachBook"
      @search="getSearch(item.bookName)"
      @cancel="onCancel"
    />

    <!-- 搜索框 start -->
    <!-- <van-search
      v-model="value"
      shape="round"
      background="#fff"
      placeholder="请输入搜索关键词"
    /> -->
    <!-- 搜索框 end -->

    <!-- bookitem -->
    <div class="book">
      <div
        class="bookitem"
        @click="bookinfo(item.id)"
        v-for="(item, index) in book"
        :key="index"
      >
        <div class="bookImg">
          <img :src="item.image" alt="" />
        </div>
        <span>{{ item.author }}</span>
        <p>{{ item.bookName }}</p>
      </div>
      <!--  -->

      <!--测试书籍数据 start  -->
      <!-- <div class="bookitem" @click="bookinfo">
        <div class="bookImg">
          <img src="../../assets/global/img/book4.jpg" alt="" />
        </div>
        <span>张嘉佳</span>
        <p>云边有个小卖部</p>
      </div>
      <div class="bookitem" @click="bookinfo">
        <div class="bookImg">
          <img src="../../assets/global/img/book1.jpg" alt="" />
        </div>
        <span>爱德华·圣奥宾</span>
        <p>梅尔罗斯</p>
      </div>
      <div class="bookitem" @click="bookinfo">
        <div class="bookImg">
          <img src="../../assets/global/img/book4.jpg" alt="" />
        </div>
        <span>张嘉佳</span>
        <p>云边有个小卖部</p>
      </div>
      <div class="bookitem" @click="bookinfo">
        <div class="bookImg">
          <img src="../../assets/global/img/book1.jpg" alt="" />
        </div>
        <span>爱德华·圣奥宾</span>
        <p>梅尔罗斯</p>
      </div>
      <div class="bookitem" @click="bookinfo">
        <div class="bookImg">
          <img src="../../assets/global/img/book4.jpg" alt="" />
        </div>
        <span>张嘉佳</span>
        <p>云边有个小卖部</p>
      </div>
      <div class="bookitem" @click="bookinfo">
        <div class="bookImg">
          <img src="../../assets/global/img/book1.jpg" alt="" />
        </div>
        <span>爱德华·圣奥宾</span>
        <p>梅尔罗斯</p>
      </div>
      <div class="bookitem" @click="bookinfo">
        <div class="bookImg">
          <img src="../../assets/global/img/book4.jpg" alt="" />
        </div>
        <span>张嘉佳</span>
        <p>云边有个小卖部</p>
      </div> -->
      <!--测试书籍数据end  -->

      <!--  -->
    </div>
    <div class="bottom" style="text-align:center;">
      <p style="color:#808DA1;font-weight: 400;">
        本服务由浙江服务网、庆元县教育局提供
      </p>
      <span style="color:#808DA1;font-weight: 400;"
        >咨询服务热线：<b style="color:#1492ff" @click="getPhone"
          >0571-88808880</b
        ></span
      >
    </div>
    <!--  -->
  </div>
</template>

<script>
import { Toast } from "vant";

const excuteBridge = () => {
  ZWJSBridge.onReady(() => {
    console.log("初始化完成后，执行bridge方法");
  });
};

// 关闭新开窗口
// const closeNewWindow = () => {
//   excuteBridge();
//   console.log("**** begin closeNewWindow() ****");

//   ZWJSBridge.close()
//     .then((result) => {
//       console.log("#### ZWJSBridge.close() log. ####");
//       console.log(result);
//     })
//     .catch((error) => {
//       console.log("#### ZWJSBridge.close() error. ####");
//       console.log(error);
//     });
//   console.log("**** exit closeNewWindow() ****");
// };
// closeNewWindow();

//

// 埋点
// 单页应用 或 “单个页面”需异步补充 PV 日志参数还需进行如下埋点：
aplus_queue.push({
  action: "aplus.setMetaInfo",
  arguments: ["aplus-waiting", "MAN"],
});
// 单页应用路由切换后 或 在异步获取到 pv 日志所需的参数后再执行 sendPV：
aplus_queue.push({
  action: "aplus.sendPV",
  arguments: [
    { is_auto: false },
    {
      // 自定义 PV 参数 key-value 键值对（只能是这种平铺的 json，不能做多层 嵌套），如：
      miniAppId: "2001886320",
    },
  ],
});

export default {
  data() {
    return {
      value: "",
      book: "",
      text: "",
      author: "",
      bookName: "",
      serachBook: "",
    };
  },
  methods: {
    // 返回首页
    onClickRight() {
      Toast("返回首页");
      this.$route.push("/home");
    },
    //拨打电话
    getPhone() {
      // window.location.href = "tel:0571-88808880";
      ZWJSBridge.phoneCall({
        corpId: "0571-88808880",
      })
        .then((res) => {
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 路由跳转--传参数id
    bookinfo(id) {
      console.log(id);
      this.$router.push({
        path: "/book",
        query: { id: id },
      });
    },
    // mgop 首页显示
    getBook() {
      console.log("首页");
      const book = async () => {
        const res = await this.mgopfn("mgop.educational.system.select");
        console.log(res);
        this.book = res.data.bookinfo;
      };
      book();
    },
    //mgop搜索
    getSearch() {
      // this.$router.push({
      //   path: this.$route.path,
      // });
      // const params = new URLSearchParams();
      // params.append("bookName", this.bookName);
      const searchBar = async () => {
        const res = await this.mgopfn("mgop.educational.system.vague", {
          bookName: this.serachBook,
        });
        console.log("vague结果:" + res);
        this.book = res.data.bookInfos;
      };
      searchBar();
    },
    // 取消-提醒
    onCancel() {
      Toast("取消");
    },
  },
  mounted() {
    // this.getBook();
    this.getSearch();
    excuteBridge();
  },
};
</script>

<style scoped>
@media screen and (min-width: 320px) {
  .van-search__content--round {
    border: 2px solid #a6a6a6;
  }
  /*deep */
  .van-icon .van-icon-search {
    color: #a6a6a6;
  }
  .book {
    margin-top: 100px;
    width: 100%;
    height: 100%;
    padding-top: 10px;
    padding-bottom: 45px;
    /* background: red; */
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    align-items: flex-start;
    align-content: flex-start;
    margin-bottom: 50px;
    /* z-index: -10000; */
    position: relative;
    top: -50px;
  }
  .book:after {
    content: "";
    width: 45%;
  }
  /* bookitem */
  .bookitem {
    width: 45%;
    height: 40%;
    /* background: lightblue; */
    float: left;
    /* z-index: -10000; */
  }

  .bookImg {
    width: 90%;
    height: 180px;
    background: #ffffff;
    margin: 0 auto;
    border-radius: 10px;
  }
  .bookImg img {
    width: 100%;
    height: 100%;
    border-radius: 10px;
  }
  .bookitem span {
    margin-top: 10px;
    display: block;
    color: rgba(80, 80, 80, 1);
    font-size: 10px;
    margin-left: 10px;
  }
  .bookitem p {
    margin-top: 4px;
    font-size: 12px;
    font-weight: bold;
    margin-left: 10px;
  }
  .van-search {
    width: 100%;
    position: fixed;
    z-index: 1000;
    margin-top: -100px;
    margin-bottom: 0;
  }
  .bottom {
    font-size: 10px;
    position: relative;
    bottom: 100px;
    width: 100%;
    /* z-index: 1;
    position: flex;
    width: 100%;
    height: 70px;
    background: pink;
    display: inline-block;*/
  }
  .bottom p {
    margin-bottom: 0;
  }
}
/* iphone6/7/8 */
@media screen and (min-width: 375px) {
  .van-search__content--round {
    border: 2px solid #a6a6a6;
  }
  /*deep */
  .van-icon .van-icon-search {
    color: #a6a6a6;
  }
  .book {
    margin-top: 100px;
    width: 100%;
    height: 100%;
    padding-top: 10px;
    padding-bottom: 40px;
    /* background: red; */
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    align-items: flex-start;
    align-content: flex-start;
    margin-bottom: 50px;
    /* z-index: -10000; */
    position: relative;
    top: -40px;
  }
  /* bookitem */
  .bookitem {
    width: 45%;
    height: 40%;
    /* background: lightblue; */
    float: left;
    /* z-index: -10000; */
  }
  .bookImg {
    width: 90%;
    height: 200px;
    background: #ffffff;
    margin: 0 auto;
    border-radius: 10px;
  }
  .bookitem img {
    width: 100%;
    height: 100%;
    border-radius: 10px;
  }
  .bookitem span {
    margin-top: 10px;
    display: block;
    color: rgba(80, 80, 80, 1);
    font-size: 12px;
    margin-left: 10px;
  }
  .bookImg p {
    margin-top: 4px;
    font-size: 14px;
    font-weight: bold;
    margin-left: 10px;
  }
  .van-search {
    width: 100%;
    /* margin-top: 45px; */
    position: fixed;
    z-index: 1000;
    margin-top: -100px;
  }
  .bottom {
    font-size: 11px;
    /* position: fixed;
    margin: auto;
    left: 0;
    right: 0; */
    /* top: 0; */
    /* bottom: 90px; */
    width: 100%;
    position: relative;
    bottom: 110px;
  }
  .bottom p {
    margin-bottom: 0;
  }
}
/* iphone6/7/8 Plus */
@media screen and (min-width: 414px) {
  /deep/.van-field__left-icon {
    margin-right: 4px;
    margin-top: 2px;
  }
  /deep/.van-field__left-icon .van-icon {
    margin-top: 4px;
    font-size: 20px !important;
  }
  .van-search {
    width: 100%;
    height: 10%;
    /* margin-top: 45px; */
    position: fixed;
    z-index: 1000;
    margin-top: -120px;
  }
  .van-search__content--round {
    border: 2px solid #a6a6a6;
    height: 45px;
  }
  /deep/.van-field__control {
    width: 100%;
    height: 30px;
  }
  /deep/ .van-icon .van-icon-search {
    color: #a6a6a6;
  }
  .book {
    margin-top: 120px;
    width: 100%;
    height: 100%;
    padding-top: 10px;
    padding-bottom: 40px;
    /* background: red; */
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    align-items: flex-start;
    align-content: flex-start;
    margin-bottom: 50px;
    /* z-index: -10000; */
    position: relative;
    top: -50px;
  }
  /* bookitem */
  .bookitem {
    width: 45%;
    height: 40%;
    /* background: lightblue; */
    float: left;
    /* z-index: -10000; */
  }
  .bookImg {
    width: 90%;
    height: 220px;
    background: #ffffff;
    margin: 0 auto;
    border-radius: 10px;
  }
  .bookitem img {
    width: 100%;
    height: 100%;
    border-radius: 10px;
  }
  .bookitem span {
    margin-top: 10px;
    display: block;
    color: rgba(80, 80, 80, 1);
    font-size: 14px;
    margin-left: 10px;
  }
  .bookImg p {
    margin-top: 4px;
    font-size: 14px;
    font-weight: bold;
    margin-left: 10px;
  }
  .bottom {
    font-size: 12px;
    /* position: fixed;
    margin: auto;
    left: 0;
    right: 0; */
    /* top: 0; */
    /* bottom: 90px; */
    width: 100%;
    position: relative;
    bottom: 110px;
  }
  .bottom p {
    margin-bottom: 0;
  }
}
/* ipad */
@media screen and (min-width: 768px) {
  /deep/.van-nav-bar {
    width: 100%;
    line-height: 22px;
    font-size: 22px;
  }
  /deep/.van-nav-bar__content {
    height: 60px !important;
  }
  /deep/.van-nav-bar__title {
    font-size: 24px !important;
  }
  /deep/.van-field__left-icon {
    margin-right: 4px;
    margin-top: 5px;
  }
  /deep/.van-field__left-icon .van-icon {
    margin-top: 4px;
    font-size: 28px !important;
  }
  .van-search {
    width: 100%;
    /* margin-top: 45px; */
    position: fixed;
    z-index: 1000;
    margin-top: -140px;
    color: #a6a6a6;
  }
  .van-search__content--round {
    border: 2px solid #a6a6a6;
    height: 60px;
  }
  /deep/.van-field__control {
    height: 50px;
    line-height: 50px;
    font-size: 22px;
    margin-left: 20px;
  }
  /deep/ .van-icon .van-icon-search {
    color: #a6a6a6;
  }

  /deep/.van-field__left-icon .van-icon {
    margin-top: 4px;
    font-size: 20px;
  }
  .book {
    margin-top: 140px;
    width: 100%;
    height: 100%;
    padding-top: 40px;
    padding-bottom: 45px;
    /* background: red; */
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    align-items: flex-start;
    align-content: flex-start;
    margin-bottom: 50px;
    /* z-index: -10000; */
    position: relative;
    top: -70px;
  }
  /* bookitem */
  .bookitem {
    width: 45%;
    height: 55%;
    /* background: lightblue; */
    float: left;
    /* z-index: -10000; */
  }
  .bookImg {
    width: 90%;
    height: 400px;
    background: #ffffff;
    margin: 0 auto;
    border-radius: 10px;
  }
  .bookImg img {
    width: 100%;
    height: 100%;
    border-radius: 10px;
  }
  .bookitem span {
    margin-top: 10px;
    display: block;
    color: rgba(80, 80, 80, 1);
    font-size: 18px;
    margin-left: 20px;
  }
  .bookitem p {
    margin-top: 4px;
    font-size: 22px;
    font-weight: bold;
    margin-left: 20px;
  }
  .bottom {
    font-size: 18px;
    /* position: fixed;
    margin: auto;
    left: 0;
    right: 0; */
    /* top: 0; */
    /* bottom: 130px; */
    width: 100%;
    position: relative;
    bottom: 140px;
  }
  .bottom p {
    margin-bottom: 0;
  }
}
@media screen and (min-width: 1024px) {
  /deep/.van-nav-bar {
    width: 100%;
    line-height: 22px;
    font-size: 26px;
    /* background: pink; */
  }
  /deep/.van-nav-bar__content {
    height: 80px !important;
  }
  /deep/.van-nav-bar__title {
    font-size: 26px !important;
  }
  /deep/.van-field__left-icon {
    margin-right: 4px;
    margin-top: 5px;
  }
  /deep/.van-field__left-icon .van-icon {
    margin-top: 4px;
    font-size: 28px !important;
  }
  .van-search {
    width: 100%;
    /* margin-top: 45px; */
    position: fixed;
    z-index: 1000;
    margin-top: -140px;
    color: #a6a6a6;
  }
  .van-search__content--round {
    border: 2px solid #a6a6a6;
    height: 60px;
  }
  /deep/.van-field__control {
    height: 50px;
    line-height: 50px;
    font-size: 22px;
    margin-left: 20px;
  }
  /deep/ .van-icon .van-icon-search {
    color: #a6a6a6;
  }

  /deep/.van-field__left-icon .van-icon {
    margin-top: 4px;
    font-size: 20px;
  }
  .book {
    width: 100%;
    height: 100%;
    padding-top: 60px;
    padding-bottom: 45px;
    /* background: red; */
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    align-items: flex-start;
    align-content: flex-start;
    margin-bottom: 50px;
    /* z-index: -10000; */
    position: relative;
    top: -70px;
  }
  /* bookitem */
  .bookitem {
    width: 45%;
    height: 55%;
    /* background: lightblue; */
    float: left;
    /* z-index: -10000; */
  }
  .bookImg {
    width: 90%;
    height: 600px;
    background: #ffffff;
    margin: 0 auto;
    border-radius: 20px;
  }
  .bookImg img {
    width: 100%;
    height: 100%;
    border-radius: 20px;
  }
  .bookitem span {
    margin-top: 10px;
    display: block;
    color: rgba(80, 80, 80, 1);
    font-size: 22px;
    margin-left: 20px;
  }
  .bookitem p {
    margin-top: 4px;
    font-size: 28px;
    font-weight: bold;
    margin-left: 20px;
  }
  .bottom {
    font-size: 20px;
    /* position: fixed;
    margin: auto;
    left: 0;
    right: 0; */
    /* top: 0; */
    /* bottom: 150px; */
    width: 100%;
    position: relative;
    bottom: 150px;
  }
  .bottom p {
    margin-bottom: 0;
  }
}
</style>
